package com.ahwei.util;

import java.util.Scanner;

/**
 * @author：ahwei163@qq.com
 * Email: @qq1632957243
 * @date: 202*-01-13 14:58
 * @description: Scanner工具类！
 */
public class ScannerUtils {
    /**
     * 获取指定返回的输入数字
     * @param min ·
     * @param max ·
     * @return ·
     */
    public static int getInt(int min, int max) {
        Scanner sc = new Scanner(System.in);
        if (!sc.hasNextInt()) {
            return getInt(min, max);
        }
        int num = sc.nextInt();
        if (num < min || num > max) {
            return getInt(min, max);
        }
        return num;
    }

    public static String next() {
        return new Scanner(System.in).next();
    }

    public static String nextLine() {
        return new Scanner(System.in).nextLine();
    }

    /**
     * 获取双精度数
     * @return ·
     */
    public static double getDouble(double min) {
        Scanner sc = new Scanner(System.in);
        double num = sc.nextDouble();
        if (num < min) {
            return getDouble(min);
        }
        return num;
    }

    public static int getInt(int min) {
        Scanner sc = new Scanner(System.in);
        if (!sc.hasNextInt()) {
            return getInt(min);
        }
        int num = sc.nextInt();
        if (num < min) {
            return getInt(min);
        }
        return num;
    }
}
